package com.guodi.model.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guodi.model.constant.CommonConst;
import com.guodi.model.entity.MdlModel;
import com.guodi.model.mapper.MdlModelMapper;
import com.guodi.model.service.IMdlModelService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @描述：模型信息表 服务类
 * @作者: 代鹏刚
 * @日期: 2020-06-17
 */
@Service
public class MdlModelServiceImpl extends ServiceImpl<MdlModelMapper, MdlModel> implements IMdlModelService{

    @Resource
    private MdlModelMapper mdlModelMapper;

    @Override
    public IPage<MdlModel> listByEntity(Page page, MdlModel mdlModel, CommonConst commonConst) {
        QueryWrapper<MdlModel> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(commonConst.getKeyWord())){
            queryWrapper.like("name",commonConst.getKeyWord());
        }
        if(StringUtils.isNotBlank(commonConst.getSortType())){
            if(commonConst.getSortType().equals("1")){
                if(commonConst.getSortMethod().equals("1")){
                    queryWrapper.orderByDesc("create_time");
                }else {
                    queryWrapper.orderByAsc("create_time");
                }
            }else {
                if(commonConst.getSortMethod().equals("1")){
                    queryWrapper.orderByDesc("name");
                }else {
                    queryWrapper.orderByAsc("name");
                }
            }
        }
        IPage<MdlModel> modelIPage = this.page(page,queryWrapper);
        return modelIPage;
    }

    @Override
    public List<MdlModel> listModelByModelId(String analysisModelId, String name) {
        return mdlModelMapper.listModelByModelId(analysisModelId,name);
    }

    @Override
    public List<MdlModel> getUnClassifyList(Page page, String parentId, String name) {
        return mdlModelMapper.getUnClassifyList(parentId,name);
    }
}